package com.tjetc.controller;

import com.tjetc.common.JsonResult;
import com.tjetc.entity.Category;
import com.tjetc.entity.DishType;
import com.tjetc.service.CategoryService;
import com.tjetc.service.DishTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/type")
public class TypeController {
    @Autowired
    DishTypeService dishTypeService;

    @Autowired
    CategoryService categoryService;

    /**
     * 列出所有的菜品类别
     * @return 返回类别列表
     */
    @RequestMapping("list")
    public JsonResult list(){
        return categoryService.selectAll();
    }

    /**
     * 列出所有的父类别
     * @return 返回父类别列表
     */
    @RequestMapping("listType")
    public JsonResult listType() {
        return dishTypeService.getAll();
    }

    /**
     * 更新类别的信息
     * @param type 输入类别的信息
     * @return 返回更新结果
     */
    @RequestMapping("update")
    public JsonResult updateType(Category type) {
        return categoryService.update(type);
    }

    /**
     * 删除订单
     * @param typeId 需要删除的订单id
     * @return 返回删除的结果JsonResult
     */
    @RequestMapping("delete")
    public JsonResult deleteType(@RequestParam("id") Integer typeId) {
        return new JsonResult<>(0, "", categoryService.deleteById(typeId));
    }

    /**
     * 添加类别接口
     * @param type 想要添加的Category
     * @return 返回添加状态
     */
    @RequestMapping("add")
    public JsonResult addType(Category type) {
        return new JsonResult(0, "", categoryService.insert(type));
    }
}
